/**
 * 扩展Array的add方法
 */
Array.prototype.add=function(obj){
	if(obj===null){
		return this;
	}	
	if(Ext.isArray(obj)){
		for( var i=0;i<obj.length;i++ ){
			this.push(obj[i]);
		}
	}else{
		this[this.length]=obj;
	}
	
	return this;
}
//设置url项目名称
Ext.ux.PROJECT_NAME = "mobile";

Ext.ux.IncludeFile=function(){
	this.head=document.getElementsByTagName('head').item(0); 
}
Ext.ux.IncludeFile.prototype={
	/**
	 * 添加js
	 * @param file  文件路径
	 * @param isAbs file是否是绝对路径
	 */
	script:function(file,isAbs){
		var new_element;
	    new_element=document.createElement("script");
	    new_element.setAttribute("type","text/javascript");
	    if(isAbs){
	    	new_element.setAttribute("src",this.getAbsFile(file));
	    }else{
	    	new_element.setAttribute("src",file);
	    }
	    
	    void(this.head.appendChild(new_element));
	},
	/**
	 * 通过绝对路径添加js
	 * @param  file
	 */
	scriptAbs:function(file){
		this.script(file,true);
	},
	/**
	 * 添加css
     * @param file  文件路径
     * @param isAbs file是否是绝对路径
     */
	link:function(file,isAbs){
		var new_element;
	    new_element=document.createElement("link");
	    new_element.setAttribute("type","text/css");
	    new_element.setAttribute("rel","stylesheet");
	    if(isAbs){
	    	new_element.setAttribute("href",this.getAbsFile(file));
	    }else{
	    	new_element.setAttribute("href",file);
	    }
	    
	    void(this.head.appendChild(new_element));
	},
	/**
     * 通过绝对路径添加css
     * @param  file
     */
	linkAbs:function(file){
		this.link(file,true);
	},
	getAbsFile:function(file){
		return "http://"+location.host+"/"+Ext.ux.PROJECT_NAME+"/"+file;
	}
}

Ext.apply(Ext,{
	//往Ext中添加在js中可以导入js文件
	script:function(file){
		var includeFile = new Ext.ux.IncludeFile();
		includeFile.script(file);
	},
	scriptAbs:function(file){
        var includeFile = new Ext.ux.IncludeFile();
        includeFile.scriptAbs(file);
    },
	//往Ext中添加在js中可以导入css文件
	link:function(file){
		var includeFile = new Ext.ux.IncludeFile();
		includeFile.link(file);
	},
	linkAbs:function(file){
        var includeFile = new Ext.ux.IncludeFile();
        includeFile.linkAbs(file);
    },
	/**
	 * 把对象的属性转换为字符窜
	 * @param	obj		要进行转换的对象
	 * @return 	Object	进行转换后的对象
	 */
	propertisEncode:function(obj){
		var newObj = {};
		for (var i in obj){
			if(obj.hasOwnProperty(i)){
				newObj[i] = Ext.encode(obj[i]);
			}
		}
		
		return newObj;
	}
});


//填充图片的本地应用如果不加此项，会重官网上下载此图片，影响速度
Ext.BLANK_IMAGE_URL='../resources/images/default/s.gif';
//在ie中默认的宽度不够
Ext.apply(Ext.MessageBox,{
	alert:function(title, msg, fn, scope){
		this.show({
	        title : title,
	        msg : msg,
	        buttons: this.OK,
	        minWidth:200,
	        fn: fn,
	        scope : scope
	    });
	    return this;
	}
});
//添加Ext的提示框功能
Ext.QuickTips.init();